import { TextAreaField } from '@aws-amplify/ui-react';
import { TextAreaFieldDemo } from './demo';
import {
DefaultRequiredTextAreaFieldExample,
DefaultTextAreaExample,
RequiredTextAreaFieldExample,
TextAreaMaxLengthExample,
TextAreaResizableExample,
TextAreaRowsExample,
TextAreaSizeExample,
TextAreaFieldDescriptiveExample,
TextAreaFieldStatesExample,
TextAreaFieldStylePropsExample,
TextAreaFieldThemeExample,
TextAreaFieldValidationErrorExample,
TextAreaFieldVariationExample,
} from './examples';
import { Example, ExampleCode } from '@/components/Example';
import { Fragment } from '@/components/Fragment';
import { ComponentStyleDisplay } from '@/components/ComponentStyleDisplay';
import ThemeExample from '@/components/ThemeExample.mdx';
## Demo
## Usage
Import the `TextAreaField` component and styles and provide a `label` for accessibility/usability.
```jsx file=./examples/DefaultTextAreaExample.tsx
```
### Accessibility
The form primitives are accessible by default. A matching `label` HTML element will be connected to the form control -- simply provide a `label` prop with a `string` or `ReactNode`. If no `id` is provided, one will be automatically generated and connected to both `label` and form control elements.
### Resizeable
For a resizeable multiline field, use `resize` prop. Common values are `horizontal`, `vertical`, `both`. See [MDN resize docs](https://developer.mozilla.org/en-US/docs/Web/CSS/resize) for supported values.
```jsx file=./examples/TextAreaResizableExample.tsx
```
### Size
To change the general size, use the `size` prop. Available options are `small`, none (default), and `large`.
```jsx file=./examples/TextAreaSizeExample.tsx
```
### Rows
To change the number of rows of text displayed, use the `rows` prop with desired number.
```jsx file=./examples/TextAreaRowsExample.tsx
```
### Maximum length
To enforce a maximum length of multiline text, use the `maxLength` prop.
```jsx file=./examples/TextAreaMaxLengthExample.tsx
```
### Variations
There are two variation styles available: default and `quiet`.
```jsx file=./examples/TextAreaFieldVariationExample.tsx
```
### Descriptive text
To provide additional descriptive text of requirements of the field, use the `descriptiveText` field:
```jsx file=./examples/TextAreaFieldDescriptiveExample.tsx
```
### States
The available `TextAreaField` states include `isDisabled` and `isReadOnly`. A disabled field will be not be focusable not mutable and will not be submitted with form data. A readonly field cannot be edited by the user.
```jsx file=./examples/TextAreaFieldStatesExample.tsx
```
### Required fields
Use the `isRequired` prop to specify a required field.
```jsx file=./examples/DefaultRequiredTextAreaFieldExample.tsx
```
There is no default styling for required fields. Customize the `label` or `descriptiveText` to instruct the form user of the required field.
```jsx file=./examples/RequiredTextAreaFieldExample.tsx
```
### Validation error styling
Use the `hasError` and `errorMessage` fields to mark a `TextAreaField` with a validation error.
```jsx file=./examples/TextAreaFieldValidationErrorExample.tsx
```
## CSS Styling
```tsx file=./examples/TextAreaFieldThemeExample.tsx
```
### Target classes
### Global styling
To override styling on all TextAreaField primitives, you can set the Amplify CSS variables with the built-in `.amplify-textareafield` class.
```css
/* styles.css */
.amplify-textareafield {
--amplify-components-fieldcontrol-border-color: rebeccapurple;
}
```
### Local styling
To override styling on a specific TextAreaField, you can use a class selector or style props.
_Using a class selector:_
```css
/* styles.css */
.custom-textareafield-class .amplify-textarea {
border-radius: 0;
}
```
_Using style props:_
All style props will be applied to the [`Flex`](flex) wrapper of the `TextAreaField`. To style the `textarea` of the `TextAreaField`, you can pass a `inputStyles` prop with the style props you want to apply to the input.
```jsx file=./examples/TextAreaFieldStylePropsExample.tsx
```